# 1.导包
import pymysql
from pprint import pprint
# 建立连接
conn =pymysql.connect(host='localhost',port=3306,user='root',password='root',charset='utf8',database='test01')
cursor=conn.cursor()
#
# try:
#     sql='insert into student(`stu_no`,`stu_name`,`stu_age`,`class_id`,`money`) values("itsrc-024","葫芦娃",18,11,45000)'
#     rows=cursor.execute(sql)
#     print(f'受影响的行数为{rows}')
#     print(cursor.lastrowid)
#     conn.commit()#提交
# except Exception as  e:
#     print(e)
#     conn.rollback()
# finally:
#     cursor.close()
#     conn.close()

try:
    sql1='delete from student where stu_name="葫芦娃";'
    rows=cursor.execute(sql1)
    print(f'受影响的行数为{rows}')
    conn.commit()#提交
except Exception as  e:
    print(e)
    conn.rollback()
finally:
    cursor.close()
    conn.close()
#

# try:
#     sql1='update student set money =500 where stu_name="曹操";'
#     rows=cursor.execute(sql1)
#     print(f'受影响的行数为{rows}')
#     conn.commit()#提交
# except Exception as  e:
#     print(e)
#     conn.rollback()
# finally:
#     cursor.close()
#     conn.close()



